<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <title>通知设置</title>
    <link rel="stylesheet" href="../css/ydui.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../iconfont/iconfont.css">
    <script src="../js/ydui.flexible.js"></script>
</head>

<body>
    <div class="g-view noticesetupPage" id="noticesetupPage">
        <div class="m-cell bornone">
            <label class="cell-item">
                <span class="cell-left">接受询盘消息</span>
                <label class="cell-right">
                    <img id="is_receive" class="min-swich" :src="data_obj.is_receive" alt="" srcset="">
                </label>
            </label>
        </div>
        <div class="m-cell bornone">
            <span class="font-c9 cell-item">关闭后将不会像您通知最新询盘商机</span>
        </div>
        <div class="m-cell">
            <label class="cell-item">
                <span class="cell-left">设置时间段</span>
                <label class="cell-right">
                    <img id="is_settime" class="min-swich" :src="data_obj.is_settime" alt="" srcset="">
                </label>
            </label>
        </div>
        <div class="m-cell">
            <label class="cell-item">
                <span class="cell-left">开始时间：</span>
                <label class="cell-right">
                    <input id="starttime" :value="data_obj.start_time" class="cell-input" type="time" name="radio" />
                </label>
            </label>
        </div>
        <div class="m-cell">
            <label class="cell-item">
                <span class="cell-left">结束时间：</span>
                <label class="cell-right">
                    <input id="endtime" :value="data_obj.end_time" class="cell-input" type="time" name="radio" />
                </label>
            </label>
        </div>
        <div class="setup-tishi">
            <p>设置后。将只在时间段内发送通知</p>
            <p>负责地区（可多选）：
                <span>只推送选择地区的商机，变更后请点击底部的保存按钮</span>
            </p>
        </div>
        <div class="area" style="margin-bottom: 1rem" id="area">
            <div class="m-cell">
                <label class="cell-item" v-for="(item, index) in province_arry" :key="index">
                    <span class="cell-left">{{item.name}}</span>
                    <label class="cell-right">
                        <input :checked="item.ischecked" :value="item.id" type="checkbox" name="checkbox" />
                        <i class="cell-checkbox-icon"></i>
                    </label>
                </label>
            </div>
        </div>
        <button @click="noticeSubmit()" class="btn-block btn-primary">保存设置</button>
    </div>
    <footer class="m-tabbar tabbar-fixed">
        <a href="../index.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:25px" class="icon iconfont">&#xe617;</i>
            </span>
            <span class="tabbar-txt">询盘商机</span>
        </a>
        <a href="../setup.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:20px" class="icon iconfont">&#xe698;</i>
            </span>
            <span class="tabbar-txt">设置商机</span>
        </a>
        <a href="../release.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:22px" class="icon iconfont">&#xe662;</i>
            </span>
            <span class="tabbar-txt">发布商机</span>
        </a>
        <a href="../vip.html" class="tabbar-item tabbar-active">
            <span class="tabbar-icon">
                <i style="font-size:25px" class="icon iconfont">&#xe67e;</i>
            </span>
            <span class="tabbar-txt">会员中心</span>
        </a>
    </footer>
    <script src="../js/jquery-3.3.1.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../js/ydui.js"></script>
    <script src="../js/nuoxia.js"></script>
    <script>
        window.onload = function () {
            var token = window.localStorage.getItem("token")
            var noticesetupPage = new Vue({
                el: "#noticesetupPage",
                data: {
                    province_arry: [],
                    data_obj:{}
                },
                filters: {

                },
                mounted: function () {
                    this.addresslist();
                },
                methods: {
                    addresslist: function () {
                        var _this = this;
                        var checkbox_arry = [];
                        $.ajax({
                            type: "get",
                            url: paraurl + "api/user/noticeset?tm=" + tm + "&token=" + token,
                            success: function (data) {
                                if (data.code == 1) {
                                    var data_obj = data.data;
                                    if (data_obj.is_receive == 1) {
                                        data_obj.is_receive = "../icon/on.png";
                                    } else {
                                        data_obj.is_receive = "../icon/off.png";
                                    }
                                    if (data_obj.is_settime == 1) {
                                        data_obj.is_settime = "../icon/on.png";
                                    } else {
                                        data_obj.is_settime = "../icon/off.png";
                                    }
                                    _this.data_obj=data_obj;
                                    var checkbox_arry=data_obj.manager_area.split(",")
                                    $.ajax({
                                        type: "get",
                                        url: paraurl + "api/region/province?tm=" + tm,
                                        success: function (data) {
                                            if (data.code == 1) {
                                                var type_arry = data.data;
                                                for (var i = 0; i < type_arry.length; i++) {
                                                    for (var j = 0; j < checkbox_arry.length; j++) {
                                                        if (type_arry[i].id == checkbox_arry[j]) {
                                                            type_arry[i].ischecked = true;
                                                        }
                                                    }
                                                }
                                                _this.province_arry = type_arry;
                                            }
                                        }
                                    })
                                }
                            }
                        })
                    },
                    noticeSubmit: function () {
                        var is_receive = $("#is_receive").attr("src");
                        if (is_receive == "../icon/on.png") {
                            is_receive = 1;
                        } else {
                            is_receive = 0;
                        }
                        var is_settime = $("#is_settime").attr("src");
                        if (is_settime == "../icon/on.png") {
                            is_settime = 1;
                        } else {
                            is_settime = 0;
                        }
                        var start_time = $("#starttime").val();
                        var end_time = $("#endtime").val();
                        var names = $("#area input[name='checkbox']");
                        var values = [];
                        for (var i = 0; i < names.length; i++) {
                            if (names[i].checked) {
                                values.push(names[i].value)
                            }
                        }
                        var manager_area = values.toString();
                        $.ajax({
                            type: "post",
                            url: paraurl + "api/user/noticeset?token=" + token + "&tm=" + tm,
                            data: {
                                "is_receive": is_receive,
                                "is_settime": is_settime,
                                "start_time": start_time,
                                "end_time": end_time,
                                "manager_area": manager_area
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    YDUI.dialog.toast(data.msg, 'success', 2000, function () {
                                    });
                                } else {
                                    YDUI.dialog.alert(data.msg);
                                }
                            }
                        })
                    }
                }
            })
            $("#noticesetupPage").on("click", ".min-swich", function () {
                var $this = $(this);
                $this.attr("src", function () {
                    if ($this.attr("src") == "../icon/on.png") {
                        return "../icon/off.png";
                    } else {
                        return "../icon/on.png";
                    }
                })
            })
        }
    </script>
</body>

</html>